package com.neusoft;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

public class Date {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int y1 = sc.nextInt();
        int y2 = sc.nextInt();


        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");

        for (int i = y1; i <= y2; i++) {
            for (int j= 1; j <= 7; j++) {
                LocalDate localDate = LocalDate.of(i,a,j);
                if(localDate.getDayOfWeek().getValue() == c){
                    LocalDate resultDate = localDate.plusWeeks(b - 1);
                    if(resultDate.getMonth().getValue() == a){
                        String result = resultDate.format(dateTimeFormatter);
                        System.out.println(result);
                    }else{
                        System.out.println("none");
                    }
                }
            }
        }
    }

}
